package com.hhit.collaborative_learning.learning;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql;
import com.hhit.collaborative_learning.entity.User;

public class GetAttentionServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String attention=request.getParameter("attention");
		String userId=request.getParameter("userId");
		String type=request.getParameter("type");
		String currentPage=request.getParameter("currentPage");
//		System.out.println(attention);
//		System.out.println(userId);
//		System.out.println(type);
		PublicDaoImplMySql dao=new PublicDaoImplMySql();
		HashMap<String, Object> map=dao.getAttention(attention, Integer.parseInt(type), Integer.parseInt(userId), currentPage);
		JSONObject json=new JSONObject();
		json.put("currentPage", map.get("currentPage"));
		JSONArray arr=new JSONArray();
		ArrayList<User> users=(ArrayList<User>) map.get("list");
		arr.addAll(users);
		json.put("list", arr);
		response.getWriter().print(json.toString());
	}

}
